package com.galo.service.controller;

import com.alibaba.fastjson.JSONObject;
import com.galo.service.common.Result;
import com.galo.service.common.ResultGenerator;
import com.galo.service.service.WirelessSwitchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 无线开关
 */
@RestController
@RequestMapping("/api/v1/switch")
public class WirelessSwitchController {

    @Autowired
    private WirelessSwitchService switchService;

    /**
     * 智能控制开关接口
     *
     * @param body
     * @return
     */
    @PostMapping("/control")
    public Result control(@RequestBody String body) {

        JSONObject object = JSONObject.parseObject(body);
        String devsn = object.getString("devsn");
        String sta = object.getString("sta");
        switchService.control(devsn, sta);
        return ResultGenerator.genSuccessResult("指令发送成功！");
    }

}
